package com.tanggh.dao.impl;


import org.hibernate.Query;
import org.springframework.stereotype.Repository;

import com.tanggh.dao.UserDao;
import com.tanggh.entity.User;

@Repository
public class UserDaoImpl extends GenericDaoImpl<User> implements UserDao {


	@Override
	public int checkEmailExist(String email) {
		String sql = "select count(id) from User u where email = ?";
		Query query =  getSession().createQuery(sql).setParameter(0, email);
		Integer count = ((Long)query.uniqueResult()).intValue();
		return count;
	}
	
	@Override
	public User findUser(User user) {
		String hql = "from User where email=:email and password=:password";
		Query query = getSession().createQuery(hql)
		.setParameter("email", user.getEmail())
		.setParameter("password", user.getPassword());
		User u = (User) query.uniqueResult();
		return u;
	}
}
